var Project = {
     items: null,
     data: null,
     createInit: function(){
        $ajax({
            url : "/user/list",
            data: {
                category: UTYPE.PROVIDER
            },
            success: function(res){
                var list = res.result.results;
                var html = '';
                for (var i = 0 ; i < list.length ; i ++){
                    html += '<option value="' + list[i]._id + '">' + list[i].username + "("+ (list[i].name?list[i].name:"无") +")" + '</option>';
                }
                $("#owner").html(html);
            }
        });
          $(".aboutCourse").click(function(){
               $ajax({
                    url: "/direction/list",
                    success: function(res){
                         var items = res.result.results;
                         var directHtml = '<select id="directSel">';
                         for (var i=0; i<items.length; i++) 
                              directHtml += '<option value="' + items[i]._id + '">' + items[i].name + '</option>';
                         directHtml += '</select>';
                         Project.coursesInit(items[0]._id,directHtml);    
                    }
               });
          });
         $("#jumpKity").click(function(){
               var data = new Object();
               data.name = $("#name").val();
               data.owner = $("#owner").val();  
               data.homework = $("#homework").text();
               data.level = $("#level").val();
               data.picture = $("#photo").val();
               data.classHour = $("#classHour").val();
              if (data.name == "") {
               return $alert("项目名称不能为空");
          };
              if (data.classHour <= "0"||data.classHour == "") {
               return $alert("时间天数不能小于“0”");
          };
               data.course = new Array();

               $("#aboutCourseList").find("tr").each(function(i){
                    data.course[i] = $(this).data("id");

               });
               $ajax({
                    url : "/project/upsert",
                    data: data,
                    success: function(res){

                         $alert("创建成功");
                         window.location.href = "projectCheck.html";
                    }
               });
          });
     },
     recommendlistClick: function(pageclickednumber){
           var cont = GetLS("cont");
           Project.recommendJump(pageclickednumber);
           $("#listPager").pager({pagenumber: pageclickednumber, pagecount: cont, buttonClickCallback: Project.recommendlistClick });
     },     
     recommendJump: function(pageno){
          var count = Res.sinCount;
          var start = (pageno-1)*count;
          $ajax({
               url: "/project/list",
               data: {
                    start : start,
                    count : count,
                    status: STATUS.PASS
               },
               success: function(res) {
                    var cont = parseInt(res.result.count/Res.sinCount);
                if((res.result.count)%Res.sinCount!=0){
                     cont++;
                }
                SetLS("cont",cont);
                if($("#listPager").children().length == 0)
                     $("#listPager").pager({ pagenumber: pageno, pagecount: cont, buttonClickCallback: Project.recommendlistClick });
                    var html = '<thead><tr>'+
                            '<th class="span3">名称</th>'+  
                            '<th class="span5">描述</th>'+
                            '<th class="span2">状态</th>'+
                            '<th class="span2">操作</th>'+
                         '</tr></thead><tbody>';

                 var items = res.result.results;
                 var desc = "";
                 var length = items && items.length || 0;
                 for (var i=0; i<length; i++) {
                    var status = items[i].recommend?STATUS.RECOMMEND:STATUS.UNRECOMMEND;
                    var operation = items[i].recommend?"取消推荐":"设为推荐";
                    var recommend = items[i].recommend?"false":"true";
                    desc = items[i].desc?items[i].desc:"无";
                    html += '<tr data-pos="'+ i +'">'+
                                   '<td>'+ items[i].name +'</td>'+   
                                   '<td class="umw15">'+ desc +'</td>'+
                                   '<td id="' + items[i]._id + '"class="umw15">'+ STATUS_HTML[status] +'</td>'+
                                   '<td>'+ 
                                   '<button data-id="' + items[i]._id + '" data-recommend="' + recommend + '" class="btn btn-primary recommendBtn" style="margin: 0 5px;">'+ operation +'</a>'+ 
                                   '</td>'+
                              '</tr>';
                 }
                 html += '</tbody>';
                 $("#tabCtn").html(html);
                 $(".recommendBtn").click(function(){
                    var id = $(this).data("id");
                    var $this = $(this);
                    var recommend = $(this).data("recommend");
                    $ajax({
                         url: "/project/recommend",
                         data: {
                              _id:id,
                              recommend:recommend
                         },
                         success: function(res){
                              // $alert("变换成功");
                              var status =  (recommend == true)?STATUS_HTML[STATUS.RECOMMEND]:STATUS_HTML[STATUS.UNRECOMMEND];
                              var operation = (recommend == true)?"取消推荐":"设为推荐";
                              var rec = !recommend;
                              $("#" + id).html(status);
                              $this.html(operation).data("recommend", rec);
                         }    
                    });
                 });
               }
          });            
     },
     recommendInit: function(){ 
           this.recommendJump(1);
     },   

     editInit: function(){
        $ajax({
            url : "/user/list",
            data: {
                category: UTYPE.PROVIDER
            },
            success: function(res){
                var list = res.result.results;
                var html = '';
                for (var i = 0 ; i < list.length ; i ++){
                    html += '<option value="' + list[i]._id + '">' + list[i].username + "("+ (list[i].name?list[i].name:"无") +")"+'</option>';
                }
                $("#owner").html(html);
                $ajax({
                   url: "/project/detail",
                   data: {
                        _id: getValue("id")
                   },
                    success: function(res){
                        var project = res.result;
                        Project.data = project;
                        $("#form").find("input[type='checkbox']:checked").each(function(i){
                            data.teachers[i] = $(this).val();
                        });
                        for (var key in project){
                            if (key == "teachers") {
                                for (var i = 0; i < project.teachers.length; i++) {
                                    $("#" + project.teachers[i]._id).attr("checked", true);
                                }
                            } else if (key == "picture") {
                                var html = '<img src="' + Core.IMG_VER + project.picture + '" style="width:100%;"><input id="photo" type="hidden" value="' + project.picture + '">';
                                $("#photoList").html(html);
                            } else {
                                if(key != "photo")
                                    $("#" + key).val(project[key]);
                            }
                        }
                        $("#homeworkList").html("作业附件:<p id='homework'>" + project.homework + "</p>");      
                        for (var i = 0 ; i < project.course.length; i ++){
                             var courseHtml =   '<tr data-id="' + project.course[i]._id + '">'+
                                                      '<td>'+ project.course[i].name +'</td>'+   
                                                      '<td class="umw15">'+ project.course[i].desc +'</td>'+
                                                      '<td><button class="btn btn-danger courseRemove" style="margin-bottom:5px"><i class="icon-remove"></i></button></td>'+
                                                '</tr>';
                             $("#aboutCourseList").append(courseHtml);
                             $(".courseRemove").click(function(){
                                  $(this).parent().parent().remove();
                             });
                        }
                        $(".aboutCourse").click(function(){
                             $ajax({
                                  url: "/direction/list",
                                  success: function(res){
                                       var items = res.result.results;
                                       var directHtml = '<select id="directSel">';
                                       for (var i=0; i<items.length; i++) 
                                            directHtml += '<option value="' + items[i]._id + '">' + items[i].name + '</option>';
                                       directHtml += '</select>';
                                       Project.coursesInit(items[0]._id,directHtml);    
                                  }
                             });
                        });
                        $("#jumpKity").click(function(){
                             var data = project;
                             data.name = $("#name").val();
                             data.owner = $("#owner").val();
                             data.homework = $("#homework").text();
                             data.level = $("#level").val();
                             data.picture = $("#photo").val();
                             data.course = new Array();
                             $("#aboutCourseList").find("tr").each(function(i){
                                  data.course[i] = $(this).data("id");
                             });
                             if($.trim($("#name").val()) == ""){
                               return $alert("项目名称不能为空");
                             }
                             $ajax({
                                  url : "/project/upsert",
                                  data: data,
                                  success: function(res){
                                       $alert("修改成功");
                                       window.location.href = "projectCheck.html";
                                  }
                             });
                        });
                        $("#jumpKityTree").click(function(){
                             window.open("minder/edit.html?id=" + project._id);
                        });
                   }
              });
            }
        });
     },
     coursesInit: function(category,directHtml){
          $ajax({
               url: "/direction/listCourse",
               data:{
                    category: category,
                    full: false
               },
               success: function(res) {
                    var items = res.result;
                    var html ='<table style="width:100%" class="table table-bordered courses"><thead><tr>'+
                                 '<th class="span4">名称</th>'+  
                                 '<th class="span6">描述</th>'+
                                 '<th class="span2"><button class="btn btn-success btn-mini selAll">全选</button></th>'+
                              '</tr></thead><tbody>';
                    var desc = "";
                    for (var i=0; i<items.length; i++) {
                         desc = items[i].desc?items[i].desc:"无";
                         html += '<tr data-pos="'+ i +'">'+
                                        '<td>'+ items[i].name +'</td>'+   
                                        '<td class="umw15">'+ desc +'</td>'+
                                        '<td><input type="checkbox" name="courseCheck" data-name="' + items[i].name + '" data-desc="' + desc + '" value="' + items[i].id + '"></td>'+
                                   '</tr>';
                    }
                    html += '</tbody></table>';
                   
                    ShowCover("课程列表","选择IT方向","","Project.courseSave()",directHtml+html);
                    $("#directSel").val(category)
                    $("#directSel").change(function(){
                         Project.coursesInit($("#directSel").val(),directHtml);      
                    });
                    $(".selAll").click(function(){
                         var flag = $(".courses").find("input[type='checkbox'][name='courseCheck']:first").prop("checked");
                         $(".courses").find("input[type='checkbox'][name='courseCheck']").each(function(){
                              $(this).prop("checked",!flag);
                         });
                    });
               }
          });  
          
     },
    courseSave: function(){
        $(".courses").find("input[type='checkbox'][name='courseCheck']:checked").each(function(){
            var $this = $(this);
            var flag = false;
            $("#aboutCourseList").find("tr").each(function(){
                if ($this.val() == $(this).data("id"))
                    flag = true;
            });
            if (!flag){
                var html =  '<tr data-id="' + $this.val() + '">'+
                                '<td>'+ $this.data("name") +'</td>'+   
                                '<td class="umw15">'+ $this.data("desc") +'</td>'+
                                '<td><button class="btn btn-danger courseRemove" style="margin-bottom:5px"><i class="icon-remove"></i></button></td>'+
                            '</tr>';
                $("#aboutCourseList").append(html);
                $(".courseRemove").click(function(){
                    $(this).parent().parent().remove();
                });
            }    
        });
        $("#cover").html("");
    },
	treeInit: function(){ 

	},
    getSuperContent: function(){
        $ajax({
            url : "/teacher/list",
            success: function(res){
                var content = "";
                var teachers = res.result.results;
                content +=  "<div class='control-group'>" + 
                            "    <label class='control-label'>选择讲师</label>" + 
                            "    <div id='teacherList' class='controls'>";
                for (var i = 0 ; i < teachers.length ; i ++){
                    content +=  "<label class='checkbox inline'>" + 
                                "    <input id='" + teachers[i]._id + "' value='" + teachers[i]._id + "' type='checkbox' name='teachers'>" + teachers[i].name + 
                                "</label>";
                }
                content +=  "    </div>" + 
                            "</div>";
                return content;     
            }
        });
    },
	getBlockHtml: function(){              
    	return  "<div class='control-group'>" + 
                "    <div class=''>" + 
                "        <label for='validation_secret'>文字介绍</label>" + 
                "    </div>" + 
                "    <div class=''>" + 
                "        <textarea id='desc' placeholder=''></textarea>" + 
                "    </div>" + 
                "</div>" + 
                "<div class='control-group'>" + 
                "    <label class='' for='validation_numbers'>要求</label>" + 
                "    <div class=''>" + 
                "        <input id='requirement' placeholder='' type='text' />" + 
                "    </div>" + 
                "</div>" + 
                "<div class='control-group'>" + 
                "    <div class=''>" + 
                "        <input id='videoBtn' type='file' name='file'>" + 
                "                   <div id='videoList'></div>" + 
                "    </div>" + 
                "</div>" + 
                "<div class='control-group'>" + 
                "    <div class=''>" + 
                "        <input id='photoBtn' type='file' name='file'>" + 
                "			 	<div id='photoList'></div>" + 
                "    </div>" + 
                "</div>" + 
                "<div class='control-group'>" + 
                "    <div class=''>" + 
                "        <input id='docsBtn' type='file'>" + 
                "			 	<div id='docsList'></div>" + 
                "    </div>" + 
                "</div>" + 
                "<div class='control-group'>" + 
                "    <div class=''>" + 
                "        <input id='attachBtn' type='file'>" + 
                "		   <div id='attachList'></div>" + 
                "    </div>" + 
                "</div>";         
	},
  getChapHtml: function(){
    return    "<div class='control-group'>" + 
                    "    <div id='chapterCont'></div>" + 
                    "    <div class='up30 tx-c'>" + 
                    "        <button onclick='Project.courseContentHtml();'>选择章节</button>" + 
                    "    </div>" + 
                    "</div>";
  },
	getPointHtml: function(){
		return    "<div class='control-group'>" + 
                    "    <div id='knowCont'></div>" + 
                    // "    <div class='up30 tx-c'>" + 
                    // "        <button onclick='Project.courseContentHtml();'>选择知识点</button>" + 
                    // "    </div>" + 
                    "</div>";
	},
     courseContentHtml: function(value){
          if (Project.data.course.length == 0)
               return $alert("该项目下暂时没有课程，无法选择知识点");
          var contentHtml = '<select id="courseSel">';
          for (var i = 0 ; i < Project.data.course.length; i ++){
               contentHtml += "<option value='" + Project.data.course[i]._id + "'>" + Project.data.course[i].name + "</option>"
          }
          contentHtml += '</select>';
          var value = value?value:Project.data.course[0]._id;
          Project.getSinCourseTree(value,contentHtml,value);
     },
     getSinCourseTree: function(_id,contentHtml,value){
          $ajax({
               url : "/course/detail",
               data : {
                    _id: _id
               },
               success: function(res){
                    var course = res.result;

                    var html ="<div class='box'><div class='box-content' style='border:none;box-shadow:none;'>" + 
                              "<div class='parentdomEvt span12 box box-nomargin'>" + 
                              "     <div class='box-header box-header-small green-background'>" + 
                              "         <div class='title'>" + 
                              "             <i class='icon-th'></i>" + 
                              "             <font id='courseName'>" + course.name + "</font>" + 
                              "         </div>" + 
                              "     </div>";
                    for (var i = 0 ; i < course.chapter.length; i ++){
                         if (course.chapter[i].category == CHAPTERTYPE.COURSEEXAM)
                              continue;
                         html += Project.getChapterHtml(course.chapter[i].name,course.chapter[i]) + "<div class='knowledgeEvt'>";
                         for (var j = 0; j < course.chapter[i].knowledge.length; j ++ ){
                              html += Project.getKnowledgeHtml(course.chapter[i].knowledge[j].name,course.chapter[i].knowledge[j]);
                         }
                         html += "</div>";
                    }
                    html += " </div></div></div>";
                    Project.showCourseTree(contentHtml + html,value);
               }
          });          
     },
     getChapterHtml: function(name,item){
          var chapterHtml =   "<div data-item='" + JSON.stringify(item) + "' data-id='" + item._id + "' data-name='" + item.name + "' data-desc='" + item.desc + "' class='chapterEvt box-content' onclick='Project.chapterCheck();'>" + 
                              "    <div class='box-toolbox box-toolbox-top' style='margin:-10px;padding:10px 5px;'>" + 
                              "    <div class='pull pull-left'>" + 
                              "         <div class='title up5 uf16'>" + name + "</div>" + 
                              "         </div>" + 
                              "    </div>" + 
                              "</div>";
        return chapterHtml;            
     },
     getKnowledgeHtml: function(name,item){
        var knowledgeHtml =  "<div data-id='" + item._id + "' data-name='" + item.name + "' data-desc='" + item.desc + "' data-target='" + item.target + "' class='box-toolbox box-toolbox-top knowEvent' style='margin:0;padding: 2% 1% 2% 10%;;background-color:#fff;border: 1px solid #dddddd;border-top:none;' >" + 
                             "   <div class='pull pull-left'>" + 
                             "        <div class='title up5 uf16 knowtitle'>" + name + "</div>" + 
                             "    </div>" + 
                             "</div>";
        return knowledgeHtml;            
     },
     toggle: function(){
          var $this = $(event.currentTarget);
          var $konw = $this.next(".knowledgeEvt");
          if ($konw.css("display") == "none")
               $konw.slideDown();
          else
               $konw.slideUp();
     },
     chapterCheck: function(){
        var $this = event?$(event.currentTarget):"";
        var _id = $this?$this.data("id"):"";
        var name = $this?$this.data("name"):"";
        var desc = $this?$this.data("desc"):"";
        var item = $this?$this.data("item"):"";

        item = item?item:"";
        SetLS("item",item);
        var html =     "<div data-id='_id' class='chapterData hide'>" + _id + "</div>" + 
                       "<div class='control-group'>" + 
                       "    <div class=''>" + 
                       "        <label for='validation_secret'>章节名称:</label>" + 
                       "    </div>" + 
                       "    <div data-id='name' class='chapterData'>" + name + "</div>" + 
                       "</div>" + 
                       "<div class='control-group'>" + 
                       "    <div class=''>" + 
                       "        <label for='validation_secret'>章节描述:</label>" + 
                       "    </div>" + 
                       "    <div data-id='desc' class='chapterData'>" + desc + "</div>" + 
                       "</div>";
        $("#chapterCont").html(html);
        saveBlockInfo();
        $("#cover").html("");
     },
     knowledgeCheck: function(){
          var $this = event?$(event.currentTarget):"";
          var _id = $this?$this.data("id"):"";
          var name = $this?$this.data("name"):"";
          var desc = $this?$this.data("desc"):"";
          var target = $this?$this.data("target"):"";
          var html =     "<div data-id='_id' class='knowData hide'>" + _id + "</div>" + 
                         "<div class='control-group'>" + 
                         "    <div class=''>" + 
                         "        <label for='validation_secret'>知识点名称:</label>" + 
                         "    </div>" + 
                         "    <div data-id='name' class='knowData'>" + name + "</div>" + 
                         "</div>" + 
                         "<div class='control-group'>" + 
                         "    <div class=''>" + 
                         "        <label for='validation_secret'>知识点描述:</label>" + 
                         "    </div>" + 
                         "    <div data-id='desc' class='knowData'>" + desc + "</div>" + 
                         "</div>" + 
                         "<div class='control-group'>" + 
                         "    <div class=''>" + 
                         "        <label for='validation_secret'>知识点目标:</label>" + 
                         "    </div>" + 
                         "    <div data-id='target' class='knowData'>" + target + "</div>" + 
                         "</div>";
          $("#knowCont").html(html);
          //saveBlockInfo();
          $("#cover").html("");
     },
     showCourseTree: function(contentHtml,value){
          var cover = "<div class='modal hide fade in' id='modal-example2' style='width:80%;left:10%;margin-left:0;' role='dialog' tabindex='-1'>" + 
                         "    <div class='modal-header'>" + 
                         "        <button class='close closeCover' data-dismiss='modal' type='button'>&times;</button>" + 
                         "        <h3>请选择知识点</h3>" + 
                         "    </div>" + 
                         "    <div class='modal-body'>" + 
                         contentHtml +
                         "    </div>" + 
                         "    <div class='modal-footer'>" + 
                         "        <button class='btn closeCover'>关闭</button>" + 
                         "    </div>" + 
                         "</div>" + 
                         "<div class='modal-backdrop fade in'></div>";
          if ($("#cover").length == 0)
               $("#content-wrapper").append('<div id="cover"></div>');
          $("#cover").html(cover);
          if (value)
               $("#courseSel").val(value);
          $(".closeCover").click(function(){
               $("#cover").html("");
          });
          $("#courseSel").change(function(){
               Project.courseContentHtml($("#courseSel").val());
          });
     },
     checkClick: function(pageclickednumber){
          var cont = GetLS("cont");
          Project.checkJump(pageclickednumber);
          $("#checkPager").pager({pagenumber: pageclickednumber, pagecount: cont, buttonClickCallback: Project.checkClick });
     },
     checkJump: function(pageno){
          var count = Res.sinCount;
          var start = (pageno-1)*count;
          var owner = CurrentUser.category == UTYPE.PROVIDER?CurrentUser._id:"";
          $ajax({
               url: "/project/list",
               data: {
                    start : start,
                    count : count,
                    owner: owner
               },
               success: function(res){
                    var project = res.result.results;
                    Project.items = project;

                    var cont = parseInt(res.result.count/Res.sinCount);
                    if((res.result.count)%Res.sinCount!=0){
                         cont++;
                    }
                    SetLS("cont",cont);
                    if($("#checkPager").children().length == 0)
                         $("#checkPager").pager({ pagenumber: pageno, pagecount: cont, buttonClickCallback: Project.checkClick });
                    var html =     "<thead>" + 
                                   "     <tr>" + 
                                   "        <th class='span3'>项目名称</th>" + 
                                   "        <th class='span2'>创建时间</th>" + 
                                   "        <th class='span2'>状态</th>" + 
                                   "        <th class='span2'>拒绝理由</th>" + 
                                   "        <th class='span3'>操作</th>" + 
                                   "    </tr>" + 
                                   "</thead>" + 
                                   "<tbody>";
                    for (var i = 0; i < project.length; i ++){
                         html +=   "<tr>" + 
                                   "   <td>" + project[i].name + "</td>" + 
                                   "   <td>" + (new Date(project[i].create)).pattern("yyyy-MM-dd") + "</td>" + 
                                   "   <td id='" + project[i]._id + "' class='prostatus'>" + STATUS_HTML[project[i].status] + "</td>" + 
                                   "   <td class='rejectDes'>" + (project[i].rejectDes?project[i].rejectDes:"") + "</td>";
                                   if(project[i].status == 1|| project[i].status == 3){
                                    html += "   <td>" + 
                                   "           <a data-num='" + i + "' data-id='" + project[i]._id + "' class='btn btn-inverse btn-mini'>编辑<i class='icon-align-left'></i></a>" + 
                                   "           <a data-num='" + i + "' data-action='PASS' class='btn btn-success btn-mini'>通过<i class='icon-ok'></i></a>" + 
                                   "           <a data-num='" + i + "' data-action='REJECT' class='btn btn-danger btn-mini'>拒绝<i class='icon-remove'></i></a>" + 
                                   "   </td>" ;
                                   }else{
                                     html += "   <td>" + 
                                   "           <a data-num='" + i + "' data-id='" + project[i]._id + "' class='btn btn-inverse btn-mini'>编辑<i class='icon-align-left'></i></a>" + 
                                   "           <a data-num='" + i + "' data-action='PASS' class='btn btn-mini'>通过<i class='icon-ok'></i></a>" + 
                                   "           <a data-num='" + i + "' data-action='REJECT' class='btn btn-mini'>拒绝<i class='icon-remove'></i></a>" + 
                                   "   </td>" ;
                                   }
                                  
                                  html += "</tr>";
                    }
                    html += "</tbody>";
                    $("#projectList").html(html);
                    $(".btn-inverse").click(function(){
                         window.location.href = "projectEdit.html?id=" + $(this).data("id");
                    });
                    $(".btn-success").click(function(){
                         var $this = $(this);
                         var item = Project.items[$(this).data("num")];
                         item.status = STATUS[$(this).data("action")];
                         item.rejectDes = "";
                         $ajax({
                              url: "/project/chengeStatus",
                              data: item,
                              success: function(res){
                                   $alert("状态变更成功");
                                   $("#"+item._id).html(STATUS_HTML[item.status]);
                                   $("#"+item._id).next(".rejectDes").text("");
                                   $this.unbind("click");
                                   $this.next().unbind("click");
                                   $this.removeClass("btn-success");
                                   $this.next().removeClass("btn-danger");
                              }
                         });
                    });
                    $(".btn-danger").click(function(){
                         var $this = $(this);
                         var item = Project.items[$(this).data("num")];
                         item.status = STATUS[$(this).data("action")];

                         if (item.status == STATUS.REJECT){
                              SetLS("projectItem",item);
                              ShowCover("提示信息","请输入拒绝理由","","Project.reject()");
                         }
                    });
               }
          });
     },
     checkInit: function(){
          Project.checkJump(1);
     },
     reject: function(){
          var item = GetLS("projectItem");
          item.rejectDes = $("#full-name").val();
          $ajax({
               url: "/project/chengeStatus",
               data: item,
               success: function(res){
                    $("#"+item._id).html(STATUS_HTML[item.status]);
                    $("#"+item._id).next(".rejectDes").text($("#full-name").val());
                    $("#cover").html("");
                    $("#"+item._id).next().next().find("a").removeClass("btn-danger");
                    $("#"+item._id).next().next().find("a").removeClass("btn-success");
                    $("#"+item._id).next().next().find("a").each(function(){
                      if($(this).attr("data-action")){
                        $(this).unbind("click");
                      }
                    });
               }
          });
     },
     manageInit: function(){
          Project.manageJump(1);
     },
     manageClick: function(pageclickednumber){
          var cont = GetLS("cont");
          Project.manageJump(pageclickednumber);
          $("#managePager").pager({pagenumber: pageclickednumber, pagecount: cont, buttonClickCallback: Project.manageClick });
     },
     manageJump: function(pageno){
          var count = Res.sinCount;
          var start = (pageno-1)*count;
          var owner = CurrentUser.category == UTYPE.PROVIDER?CurrentUser._id:"";
          $ajax({
               url: "/project/list",
               data: {
                    start : start,
                    count : count,
                    owner: owner
               },
               success: function(res){
                    var project = res.result.results;
                    Project.items = project;

                    var cont = parseInt(res.result.count/Res.sinCount);
                    if((res.result.count)%Res.sinCount!=0){
                         cont++;
                    }
                    SetLS("cont",cont);
                    if($("#managePager").children().length == 0)
                         $("#managePager").pager({ pagenumber: pageno, pagecount: cont, buttonClickCallback: Project.manageClick });
                    var html =     "<thead>" + 
                                   "     <tr>" + 
                                   "        <th class='span4'>项目名称</th>" + 
                                   "        <th class='span3'>创建时间</th>" + 
                                   "        <th class='span2'>状态</th>" + 
                                   "        <th class='span3'>操作</th>" + 
                                   "    </tr>" + 
                                   "</thead>" + 
                                   "<tbody>";
                    for (var i = 0; i < project.length; i ++){
                         html +=   "<tr>" + 
                                   "   <td>" + project[i].name + "</td>" + 
                                   "   <td>" + (new Date(project[i].create)).pattern("yyyy-MM-dd") + "</td>" + 
                                   "   <td id='" + project[i]._id + "' class='prostatus'>" + STATUS_HTML[project[i].status] + "</td>" + 
                                   "   <td>" ;
                         if(project[i].status != STATUS.PASS){
                           html += " <a data-num='" + i + "' data-id='" + project[i]._id + "' class='btn btn-inverse btn-mini'>编辑<i class='icon-align-left'></i></a>" + 
                                   " <a data-num='" + i + "' data-action='COMMIT' class='btn btn-success btn-mini'>提交<i class='icon-ok'></i></a>" ;
                         }  else{
                           html += " <a data-num='" + i + "' disabled='disabled' data-id='" + project[i]._id + "' class='btn btn-mini'>编辑<i class='icon-align-left'></i></a>" + 
                                   " <a data-num='" + i + "' disabled='disabled' data-action='COMMIT' class='btn  btn-mini'>提交<i class='icon-ok'></i></a>" ;
                         }        
                         
                         html +=  "   </td>" + 
                                  "</tr>";
                    }
                    html += "</tbody>";
                    $("#projectList").html(html);
                    $(".btn-inverse").click(function(){
                         window.open("minder/edit.html?id=" + $(this).data("id"));
                    });
                    $(".btn-success").click(function(){
                         var $this = $(this);
                         var item = Project.items[$(this).data("num")];
                         item.status = STATUS[$(this).data("action")];
                         $ajax({
                              url: "/project/chengeStatus",
                              data: item,
                              success: function(res){
                                   $alert("提交成功");
                                   $("#"+item._id).html(STATUS_HTML[item.status]);
                              }
                         });
                    });
               }
          });
     }
}
function saveBlockInfo(){
  //alert(Res.snode.getData("category"));
  //保存信息
  if (Res.snode.getData("category") == PROJECTTYPE.BLOCK){
    var category = $("#category").val();
    Res.snode.setData("category",category);
  } 
  $("#knowCont").find(".knowData").each(function(){
    $(this).text()&&Res.snode.setData($(this).data("id"),$(this).text());
  });
}



